<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Vue </title>
    <script src="./js/vue.js"></script>
</head>

<body>
    <div id="app">
        <p>总数：{{ total }}</p>
        <my-component v-model="total"></my-component>
        <button @click="handleReduce">-1</button>
    </div>
    <script>
    Vue.component('my-component', {
        props: ['value'],
        template: '<input :value="value" @input="updateValue"/>',
        methods: {
            updateValue: function(event) {
                this.$emit('input', event.target.value);
            }
        }
    });

    new Vue({
        el: '#app',
        data: {
            total: 0
        },
        methods: {
            handleReduce: function() {
                this.total--;
            }
        }
    })
    </script>
</body>

</html>
